@extends('Api.common.title')
@section('content')
    <link type="text/css" rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
    <style type="text/css">
        .layui-form-label{width: 200px;}
        .layui-input-block{margin-left: 200px;}
    </style>
<div style="padding: 15px;">
    <div class="panel panel-success">
        <div class="panel-heading">一键生成控制器、验证器、模板、数据</div>
        <div class="panel-body">
            <form class="layui-form" action="{{ URL::action('Api\DevelopController@save')}}">
                <div class="layui-form-item">
                    <label class="layui-form-label">模块</label>
                    <div class="layui-input-block">
                        <input type="radio" name="module" lay-verify="required" value="Api" title="Api" checked>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">上级菜单</label>
                    <div class="layui-input-block">
                        <select name="tab" lay-verify="required" lay-filter="table">
                            @foreach($tab as $vo)
                                <option value="{{$vo['id']}}">{{$vo['title']}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">对应数据表</label>
                    <div class="layui-input-block">
                        <select name="table" lay-verify="required" lay-filter="table">
                            <option value="">请选择表</option>
                            @foreach($tables as $vo)
                                {{$key = key($vo)}}
                                <option value="{{$vo->$key}}">{{$vo->$key}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">控制器名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" required lay-verify="required" placeholder="请输入控制器名称"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" required lay-verify="required" placeholder="请输入标题"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection
@section('content_js')
    <script type="text/javascript"  >
        $(function(){
            layui.use('form', function(){
                var form = layui.form;
                form.on('submit(formSubmit)', function (data) {
                    console.log(data.field)
                    if (!data.field.module){
                        layer.msg("请选择模块!",{anim: 6});
                    }
                    $.post(data.form.action, data.field, function (obj) {
                        if (obj.code == 200) {
                            layer.msg(obj.msg + "<br>2秒后自动刷新页面!", {anim: 4, time: 2000}, function () {
                                // console.log(obj);
                                //location.href = obj.url;
                                window.location.reload();
                            });
                        } else {
                            layer.msg(obj.msg, {anim: 6});
                        }
                    })
                    return false;
                });
            });
        })

    </script>
@endsection
